using Circus.CodeEditor;
using Circus.CodeEditor.Serialization;
using Circus.CodeEditor.TextSource;
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
namespace Circus.CodeEditor
{
	public class EditSpelling {
		private Color spellColor = EditConsts.DefaultSpellForeColor;
		private CodeEditor owner;
		[Browsable(false)]
		public event WordSpellEvent WordSpell
		{
			add
			{
				if (this.owner != null)
				{
					this.owner.Source.WordSpell += value;
				}
			}
			remove
			{
				if (this.owner != null)
				{
					this.owner.Source.WordSpell -= value;
				}
			}
		}
		[Description("Gets or sets a value representing color to draw wavy underlines under mispelled words.")]
		public virtual Color SpellColor
		{
			get
			{
				return this.spellColor;
			}
			set
			{
				if (this.spellColor != value)
				{
					this.spellColor = value;
					this.OnSpellColorChanged();
				}
			}
		}
	
		[DefaultValue(false), Description("Gets or sets a value indicating whether the document can check spelling for its content.")]
		public virtual bool CheckSpelling
		{
			get
			{
				return this.owner != null && this.owner.Source.CheckSpelling;
			}
			set
			{
				if (this.owner != null)
				{
					this.owner.Source.CheckSpelling = value;
				}
			}
		}
		[Browsable(false), Description("Gets or sets an array of chars used to separate words in a text when performing spelling check."), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual char[] SpellDelimiters
		{
			get
			{
				return (this.owner != null) ? this.owner.Source.SpellDelimiters : new char[0];
			}
			set
			{
				if (this.owner != null)
				{
					this.owner.Source.SpellDelimiters = value;
				}
			}
		}
		[Browsable(false), Description("Gets or sets \"SpellDelimiters\" as a single string."), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual string SpellDelimiterString
		{
			get
			{
				return new string(this.SpellDelimiters);
			}
			set
			{
				this.SpellDelimiters = value.ToCharArray();
			}
		}
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual bool HasSpelling
		{
			get
			{
				return this.owner != null && this.owner.Source.HasSpelling;
			}
		}
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual Hashtable SpellTable
		{
			get
			{
				return (this.owner != null) ? this.owner.Source.SpellTable : null;
			}
		}
		protected virtual void OnSpellColorChanged()
		{
			if (this.CheckSpelling || this.owner != null)
			{
				this.owner.Invalidate();
			}
		}
		public EditSpelling(CodeEditor owner)
		{
			this.owner = owner;
		}
		public bool ShouldSerializeSpellColor()
		{
			return this.spellColor != EditConsts.DefaultSpellForeColor;
		}
		public virtual void Assign(EditSpelling source)
		{
			this.CheckSpelling = source.CheckSpelling;
			this.SpellColor = source.SpellColor;
		}
		public virtual void ResetSpellColor()
		{
			this.SpellColor = EditConsts.DefaultSpellForeColor;
		}
		public virtual bool IsWordCorrect(string text)
		{
			return this.owner == null || this.owner.Source.IsWordCorrect(text);
		}
		public virtual void ResetCheckSpelling()
		{
			this.CheckSpelling = false;
		}
		public virtual void ResetSpellDelimiters()
		{
			this.SpellDelimiters = EditConsts.DefaultSpellDelimiters.ToCharArray();
		}
	}
}
